# -*- coding: utf-8 -*-
# @Time : 2022/7/3 15:08
# @Author : cheney
# @File : packet_test.py
# @Software: PyCharm
# @Site: www.cheney.cc

from pi.model.packet import packet
from pi.model.data import data
from pi.config import *
import socket
import time
import threading

while True:
    sensor_data = data()  #
    try:
        sensor_data.set_data_list([1, 2, 3])  # 获取并填充数据
    except:
        print("读取传感器error！！！")
        sensor_data.set_data_list(["error from cheney!!!", [111]])
    # sensor_data.set_trace_stack(trace_stack)
    sensor_data.set_trace_stack(["a", "b", "c"])
    # trace_stack.clear()  # todo:是否需要清空 ？ 是否需要保留历史记录 ？发送失败怎么办 ？
    _mypac = packet(src_id="", des_id="",
                    pac_type=2, ctl_type=1,
                    content=sensor_data,
                    )  # 实例化一个报文对象，并填充数据
    print(_mypac.to_bin())
    # ret = _sock.send(_mypac.to_bin())  # 对象转二进制再发送出去
    # print(">>>>> 成功发送", ret)
    time.sleep(2)  # 休息时间间隔
